class PartPurchaseDetailsController < ApplicationController

  def new
  	@part_purchase_detail = PartPurchaseDetail.new
    @part_styles = PartStyle.all
    if params[:part_id]
      @part = Part.find params[:part_id]
    end
  end

  def create
    if params[:name]
      @part = Part.create(name: params[:name])
    end
  	@part_purchase_detail = PartPurchaseDetail.new post_params
    if @part_purchase_detail.save
       redirect_to part_purchase_path(:id =>@part_purchase_detail.part_purchase.id)
    else
      render :action => 'new'
    end
  end

  def destroy
    @part_purchase_detail = PartPurchaseDetail.find params[:id]
    @part_purchase_detail.destroy
    redirect_to part_purchase_path(:id =>@part_purchase_detail.part_purchase.id)
  end

   def post_params
    params.require(:part_purchase_detail).permit(*%w(part_purchase_id part_id qty))
  end
end
